#include "clickedlabel.h"
#include <QEnterEvent>
#include <QFile>
#include <QPainter>
#include <QStyleOption>
#include "global.h"
ClickedLabel::ClickedLabel(QWidget *parent)
    : QLabel(parent)

{
    setProperty("state", "NoSelected");
    _state = "NoSelected";
    repolish(this);
    update();
}

void ClickedLabel::setSelected()
{
    setProperty("state", "Selected");
    _state = "Selected";
    repolish(this);
    update();
}

void ClickedLabel::setNoSelected()
{
    setProperty("state", "NoSelected");
    _state = "NoSelected";
    repolish(this);
    update();
}
ClickedLabel::State ClickedLabel::getState()
{
    if (_state == "Selected") {
        return Selected;
    }
    if (_state == "NoSelected") {
        return NoSelected;
    }
}

void ClickedLabel::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        // 左击
        emit sig_changeState();
    }
    if (event->button() == Qt::RightButton) {
        // 右击删除
        emit sig_del(text());
    }
}

void ClickedLabel::paintEvent(QPaintEvent *event)
{
    // 创建一个QStyleOption对象
    QStyleOption opt;
    opt.initFrom(this);
    // 创建一个QPainter对象，用于绘制
    QPainter p(this);
    // 使用样式表绘制控件
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    // 调用父类的paintEvent方法，处理其他绘制事件
    QLabel::paintEvent(event);
}
